# create copies of the unit cell
## Synopsis: multi2 TILING n1,n2,n3
BEGIN{
#  n[1]=ARGV[2]; n[2]=ARGV[3]; n[3]=ARGV[4];
#  delete ARGV[2]; delete ARGV[3]; delete ARGV[4];
#  ARGC=2;
#  if(n[1]<1){n[1]=1};
#  if(n[2]<1){n[2]=1};
#  if(n[3]<1){n[3]=1};
  smu=ARGV[2]; delete ARGV[2]; ARGC=2;
  if(smu~/x/){sep="x"};
  if(smu~/\,/){sep=","};
  split(smu,n,sep);
#  print smu,sep,n[1],n[2],n[3];
}
FNR<3{
  for(i=1;i<=5;i++){
    ba[FNR,i]=$(i);
    printf("%1i ",$(i)*n[FNR]);
  };
  printf "\n";
}
FNR==3{multi=$2*n[3];tnodes=$1*n[1]*n[2]*n[3];print tnodes,multi," # "FILENAME" "n[1]"x"n[2]"x"n[3]" (multi2)"}
FNR>3{nn++;b[nn]=$0}
END{
  for(mu=1;mu<=multi;mu++){
    for(j=1;j<=n[1];j++){
      for(k=1;k<=n[2];k++){
	for(l=1;l<=nn;l++){
	  split(b[l],a);
	  for(o=1;o<=5;o++){
	    ind=a[o]+(j-1)*ba[1,o]+(k-1)*ba[2,o];
	    printf("%1i ",ind);
	  };
	  printf "\n";
	}
      }
    }
  }
}

